package it.unicam;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class MapOverlayPath extends Overlay{
	
	
	private GeoPoint g1=null;
	private GeoPoint g2=null;
	private String whereMarker=null;

	public MapOverlayPath(GeoPoint g1,GeoPoint g2){
		this.g1=g1;
		this.g2=g2;
	}
	
	
	public MapOverlayPath(GeoPoint g1,String whereMarker){
		this.g1=g1;
		this.whereMarker=whereMarker;
	}
	
    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);                   

        Paint paint = new Paint(); 

        if(g2==null){
		      Point sp1 = new Point(); //punti in pixel della posizione iniziale dinamica
		      mapView.getProjection().toPixels(g1, sp1);       
	
		      paint.setTextSize(14);  
	         //VALORI RELATIVI A LOCATION FRIEND
	          paint.setColor(Color.GREEN);
	          paint.setStyle(Paint.Style.FILL_AND_STROKE);
            
	          if(whereMarker.equals("start")){   
	          //---add the marker start path---
	            Bitmap bmp = BitmapFactory.decodeResource(mapView.getResources(), R.drawable.green_marker);            
	            canvas.drawBitmap(bmp, sp1.x-5, sp1.y-25, paint);
	          }
	          else if(whereMarker.equals("request")){
	        	//---add the marker request path---
	             Bitmap bmp = BitmapFactory.decodeResource(mapView.getResources(), R.drawable.red_marker);            
	             canvas.drawBitmap(bmp, sp1.x-5, sp1.y-25, paint);
	         }
         
        }
        
        else{
	        //traduco i punti dinamici relativi al percorso automobilistico in pixel
	        Point sp1 = new Point(); //punti in pixel della posizione iniziale dinamica
	        Point sp2 = new Point(); //punti in pixel della posizione finale dinamica
	        mapView.getProjection().toPixels(g1, sp1);       
	        mapView.getProjection().toPixels(g2, sp2);
	        	
	        //VALORI RELATIVI ALLA LINEA DI COLLEGAMENTO
	        paint.setColor(Color.RED);
	        paint.setStrokeWidth(2);//spessore della linea di collegamento
	            
	        //Disegna la linea attraverso le coordinate in pixel (dinamici) sulla mappa
	        canvas.drawLine(sp1.x, sp1.y, sp2.x, sp2.y, paint);  
        }
           
       return true;
    }
   
    
  
    
   
    
    
}
